package com.bdq.basic.api.controller;

import cn.hutool.core.convert.Convert;
import com.bdq.basic.api.model.param.FileUploadApiParam;
import com.bdq.basic.application.model.cmd.FileUploadCmd;
import com.bdq.basic.application.service.FileAppCmdService;
import com.bdq.basic.infrastructure.config.TokenInterceptor;
import com.bdq.common.entity.UserContext;
import com.bdq.common.entity.common.CommonResult;
import com.bdq.common.utils.UserContextUtil;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.io.IOException;

/**
 * bdq-basic文件相关
 *
 * @author malei
 * @date 2024-05-02 14:30
 */
@RestController
@RequestMapping("/file")
public class FileController {

    @Resource
    private FileAppCmdService fileAppCmdService;

    /**
     * 文件上传
     *
     * @param param
     * @return
     */
    @PostMapping("/upload")
    public CommonResult<String> uploadFile(@Validated FileUploadApiParam param) throws IOException {
        String path = fileAppCmdService.uploadFile(Convert.convert(FileUploadCmd.class, param));
        return CommonResult.success(path);
    }
}
